<?php
namespace app\api\controller\xilumarket;

use app\common\controller\Api;
use think\Db;
use think\Exception;
use app\common\model\xilumarket\OrderComment;

class Comment extends Api {

    protected $noNeedLogin = ['lists'];
    protected $noNeedRight = ['*'];
    /**
     * 发布评论
     */
    public function add_comment() {
        $params = $this->request->post('');
        $params['user_id'] = $this->auth->id;
        Db::startTrans();
        try {
            $ret = OrderComment::addComment($params);
        }catch (Exception $e){
            Db::rollback();
            $this->error($e->getMessage());
        }
        Db::commit();
        $order = \app\common\model\xilumarket\Order::field("id,user_id,order_no,pay_type,total_price,pay_price,express_price,freight_type,express_name,express_code,express_no,pay_status,freight_status,receipt_status,comment_status,refund_status,order_status,createtime")
            ->with(['seller'=>function($query){
                $query->withField(['id','nickname','avatar']);
            },
                'orderProduct'=>function($query){
                    $query->field(['id','order_id','product_id','product_name','image','product_price','sum_price']);
                }])
            ->where('order.id',$params['order_id'])
            ->find();
        $this->success('评论成功', $order);

    }
}